//
//  UIimage.swift
//  Raptor
//
//  Created by Jason on 2022/4/24.
//  Copyright © 2022 IMS. All rights reserved.
//

import Foundation
import UIKit

extension UIImage {
    //instet 图片保护区域 默认拉伸中间点
   class func resizedImage(imageName : String, inset : UIEdgeInsets?) -> UIImage? {
        //防止图片拉伸变形
        var image = UIImage(named: imageName)
        let imageW = image?.size.width ?? 0
        let imageH = image?.size.height ?? 0
        var tempInset = UIEdgeInsets(top: imageH * 0.5, left: imageW * 0.5, bottom: imageH * 0.5 - 1, right: imageW * 0.5 - 1)
        if let inset = inset {
            tempInset = inset
        }
        image = image?.resizableImage(withCapInsets: tempInset, resizingMode: UIImage.ResizingMode.tile)
        return image ?? nil
    }
   
}
